package com.zzt.questionbanktotalmaneger.controller;

import com.zzt.questionbanktotalmaneger.bean.dto.*;
import com.zzt.questionbanktotalmaneger.bean.dto.query.MenuItemQueryDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private RestTemplate template;

    @Value("${menuManager.menuServiceUrl}")
    private String menuServiceUrl;

    @RequestMapping("/getMenu")
    public Result<MenuList> getAll(){
        Result<MenuList> result= template.postForObject(menuServiceUrl+"getAll",null,Result.class);
        return result;
    }

    @RequestMapping("/getMenuList")
    public Result<List< MenuItemDTO >> getMenuList(){
        Result<List< MenuItemDTO >> result=template.postForObject(menuServiceUrl+"getMenuList",null,Result.class);
        System.out.println(result);
        return result;
    }

    @RequestMapping("/getAPage")
    public PageResult<MenuItemDTO> getAPage(PageRequestMessage pageRequestMessage){
        PageResult<MenuItemDTO> pageResult=template.postForObject(menuServiceUrl+"getAPage",pageRequestMessage,PageResult.class);
        return pageResult;
    }

    @RequestMapping("/getASpecialPage")
    public PageResult<MenuItemDTO> getASpecialPage(MenuItemQueryDTO dto){
        PageResult<MenuItemDTO> pageResult=template.postForObject(menuServiceUrl+"getASpecialPage",dto,PageResult.class);
        return pageResult;
    }

    @RequestMapping("/addMenuItem")
    public Result addMenuItem(MenuItemDTO menuItemDTO){
        Result result=template.postForObject(menuServiceUrl+"addMenuItem",menuItemDTO,Result.class);
        return result;
    }

    @RequestMapping("/editMenuItem")
    public Result editMenuItem(MenuItemDTO menuItemDTO){
        Result result=template.postForObject(menuServiceUrl+"editMenuItem",menuItemDTO,Result.class);
        return result;
    }

    @RequestMapping("/deleteMenuItem")
    public Result deleteMenuItem(Long menuItemId){
        Result result=template.postForObject(menuServiceUrl+"deleteMenuItem",menuItemId,Result.class);
        return result;
    }
}
